import { Injectable } from '@nestjs/common';
const nodemailer = require("nodemailer");

@Injectable()
export class AppService {
  getHello(): string {
    let transporter = nodemailer.createTransport({
      pool: true,
      host: "smtp.exmail.qq.com",
      port: 465,
      secure: true, // use TLS
      auth: {
        user: "admin@fxpixels.site",
        pass: "Aa7114874"
      },
      logger: false,
      transactionLog: false, // include SMTP traffic in the logs
      from: 'admin <admin@fxpixels.site>',
      headers: {
        'X-Laziness-level': 1000 // just an example header, no need to use this
      },
      tls: {
        // do not fail on invalid certs
        rejectUnauthorized: false
      }
    });


    // Message object
    let message = {
      from: 'admin <admin@fxpixels.site>', // sender address
      to: "561922304@qq.com", // list of receivers
      subject: "Hello ✔", // Subject line
      text: "Hello world?", // plain text body
      html: "<b>Hello world?</b>", // html body
    }

    transporter.sendMail(message, (error, info) => {
      if (error) {
        console.log('Error occurred');
        console.log(error.message);
        return process.exit(1);
      }

      console.log('Message sent successfully!');
      // console.log(nodemailer.getTestMessageUrl(info));

      // only needed when using pooled connections
      transporter.close();
    });
    return 'Hello World!';
  }
}
